// pages/enterprise/index/news/personnel/personnel.js
import {handEnterpriseEmployee} from "../../../../../service/Message";
import Toast from "@vant/weapp/toast/toast";
Component({

    /*
    * 默认接收全局样式
    * */
    options: {
        addGlobalClass: true,
        styleIsolation: "shared",
    },

    /**
     * 组件的属性列表
     */
    properties: {
        itemInfo: {
            type: Object,
            value: {}
        }
    },

    /**
     * 组件的初始数据
     */
    data: {

    },

    /**
     * 组件的方法列表
     */
    methods: {
        /*
        * 点击按钮
        * */
        onButtonClick: async function(e) {
            let name = e.currentTarget.dataset.name;
            try {
                let id = this.data.itemInfo.id;
                let postData = {id};
                postData.eventid = name === "agree" ? 1 : 2;
                this.setData({["itemInfo." + name + "Loading"]: true})
                await handEnterpriseEmployee(postData);
                this.setData({"itemInfo.applyStatus": name === "agree" ? 1 : 2});
            } catch (e) {
                console.error(e);
                Toast({
                    type: "fail",
                    message: "操作失败",
                    context: this
                });
            } finally {
                this.setData({["itemInfo." + name + "Loading"]: false})
            }
        }
    }
})
